﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using EvaluationSystem.DAO; 

namespace EvaluationSystem
{
    public class Utility
    {
        public static string MD5(string source)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(source, "MD5"); ;
        }

        public static bool IsLogin(Page page)
        {
            return
                page.Session[LoginConstants.UserName] != null &&
                page.Session[LoginConstants.Role] != null &&
                page.Session[LoginConstants.Group] != null;
        }

        public static EvaluationSystem.DAO.Roles Role(Page page)
        {
            if (page.Session[LoginConstants.Role] == null)
            {
                return DAO.Roles.None;
            }
            else
            {
                return ((EvaluationSystem.DAO.Roles)page.Session[LoginConstants.Role]);
            }
        }

        public static Groups[] Groups(Page page)
        {
            if (page.Session[LoginConstants.Group] == null)
            {
                return new DAO.Groups[] { DAO.Groups.None };
            }
            else
            {
                return (Groups[])page.Session[LoginConstants.Group];
            }
        }
    }
}